import React, { PureComponent } from "react";
import { Form, Input, Select } from 'antd';
const Option = Select.Option;
// @connect(({ user_manage }) => ({
//   user_manage,
// }))
@Form.create()
class AddForm extends PureComponent {
  render() {
    const { id, name, password, role } = this.props.record;
    const { userManage } = this.props;
    //console.log(JSON.stringify(userManage))
    const getFieldDecorator = this.props.form.getFieldDecorator;
    const formItemLayout = {
      labelCol: { span: 4 },
      wrapperCol: { span: 12 },
    };
    return (
      <Form>
        <Form.Item
          {...formItemLayout}
          label="用户名"
          key={`${id}_name`}
        >
          {
            getFieldDecorator('name', {
              initialValue: name,
              rules: [{
                required: true,
                message: '用户名不能为空'
              }]
            })(<Input placeholder="用户名" />)
          }
        </Form.Item>
        <Form.Item
          {...formItemLayout}
          label="密码"
          key={`${id}_password`}
        >
          {
            getFieldDecorator('password', {
              initialValue: password
            })(<Input placeholder="密码" />)
          }

        </Form.Item>
        <Form.Item
          {...formItemLayout}
          label="角色"
          key={`${id}_role`}
        >
          {
            getFieldDecorator('role', {
              initialValue: role ? role.name : undefined
            })(
              <Select placeholder="请选择角色" >
                {
                  userManage.roleList !== null ? userManage.roleList.map(data => <Option key={data.id}>{data.name}</Option>) : <Option key=""></Option>
                  // user_manage.roleList.map(data => <Option value={data.id}>{data.name}</Option>)
                }
              </Select>
            )
          }
        </Form.Item>
        {/* {
          getFieldDecorator('id', {
            initialValue: id
          })(<Input type="hidden" />)
        } */}

      </Form>
    )
  }
}

export default AddForm;
